﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using NHibernate.Criterion;
using WarehouseWS.Model;

namespace WarehouseWS.BusinessLogic
{
    public class StockLogic
    {
        public void AddNewStock(Stock _stock)
        {
            using (ISession session = SessionManager.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(_stock);
                transaction.Commit();
            }
        }

        public Stock GetByStockName(string name)
        {
            using (ISession session = SessionManager.OpenSession())
            {
                Stock _stock = session
                    .CreateCriteria(typeof(Stock))
                    .Add(Restrictions.Eq("StockName", name))
                    .UniqueResult<Stock>();
                return _stock;
            }
        }

    }
}